//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<MainFrm.h>
///	@path	~/src/editor/wm/
///	@date	2008/05/20
///	@desc	Main Frame.

#pragma once

#pragma message("Compiling MainFrm.h ...")

#include "editor/editor.h"
#include "editor/wm/XFormView.h"
#include "editor/wm/XFormDialog.h"
#include "editor/wm/XFrameView.h"
#include "editor/wm/XEngineView.h"
#include "editor/wm/XEditorMain.h"
#include "editor/wm/XWindowManager.h"

namespace xeres {

	/*! 
		\class	XMainFrame
		\brief
	*/
	class XMainFrame : public CFrameWindowImpl<XMainFrame>, public CUpdateUI<XMainFrame>,
			public CMessageFilter, public CIdleHandler
	{
	public:

		DECLARE_FRAME_WND_CLASS(_T("xeres_Editor_XMainFrame") , IDR_MAINFRAME )

		virtual BOOL PreTranslateMessage(MSG* pMsg)
		{
			if( CFrameWindowImpl<XMainFrame>::PreTranslateMessage(pMsg) )
				return TRUE;
			return FALSE;
		}

		virtual BOOL OnIdle( void )
		{
			return FALSE;
		}

		BEGIN_UPDATE_UI_MAP(XMainFrame)
		END_UPDATE_UI_MAP()

		BEGIN_MSG_MAP(XMainFrame)
			MESSAGE_HANDLER(WM_CREATE, OnCreate)
			MESSAGE_HANDLER(WM_DESTROY , OnDestroy)
			MESSAGE_HANDLER(WM_SIZE , OnSize)
			MESSAGE_HANDLER(WM_MOVE , OnMove)
			MESSAGE_HANDLER(WM_PAINT , OnPaint)
			MESSAGE_HANDLER(WM_ENTERSIZEMOVE , OnEnterSizeMove)
			MESSAGE_HANDLER(WM_EXITSIZEMOVE , OnExitSizeMove)
			MESSAGE_HANDLER(WM_ERASEBKGND , OnEraseBkgnd)
			CHAIN_MSG_MAP(CUpdateUI<XMainFrame>)
			CHAIN_MSG_MAP(CFrameWindowImpl<XMainFrame>)
		END_MSG_MAP()

	// Handler prototypes (uncomment arguments if needed):
	//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

		LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
		{
			m_hWndClient = m_main.Create(m_hWnd, rcDefault, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN );

			SetMenu(NULL);

			TCHAR mainFrameText[128] = {
				_S("xedit")
			};
			SetWindowText( mainFrameText );
			
			// register object for message filtering and idle updates
			CMessageLoop* pLoop = __AppModule.GetMessageLoop();
			ATLASSERT(pLoop != NULL);
			pLoop->AddMessageFilter(this);
			pLoop->AddIdleHandler(this);

			UIAddChildWindowContainer(m_hWnd);

			return 0;
		}

		LRESULT OnDestroy( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
		{
			bHandled = FALSE;
			return 0;
		}
		LRESULT OnSize(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
		{
			bHandled = False;
			return S_OK;
		}
		LRESULT OnEnterSizeMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) {
			return m_main.GetWorkspace().GetEngineView().OnEnterSizeMove( uMsg, wParam, lParam, bHandled );
		}
		LRESULT OnExitSizeMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) {
			return m_main.GetWorkspace().GetEngineView().OnExitSizeMove( uMsg, wParam, lParam, bHandled );
		}
		LRESULT OnMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
		{
			bHandled = False;
			return S_OK;
		}
		LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
		{
			CPaintDC dc( m_hWnd );
			return S_OK;
		}
		LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
		{
			return S_OK;
		}

		/// \brief	Get main view.
		XEditorMain& GetMain( void )
		{
			return m_main;
		}

	private:

		//@ data
		XEditorMain		m_main;
	};

} // namespace xeres
